﻿
Imports System.Data.SqlClient
Public Class FrmControlRemoteDevice
    Dim tblDevice As New DataTable
    Dim tblDataConTrol As New DataTable
    Dim tblPatient As New DataTable
    Dim clsControls As New clsControls

    Private Sub FrmControlRemoteDevice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If clsControls.spGetDeviceList(tblDevice) Then
            Me.cboDevice.DataSource = Me.tblDevice.DefaultView
            Me.cboDevice.DisplayMember = "Device_Name"
            Me.cboDevice.ValueMember = "Device_ID"
            Me.cboDevice.SelectedIndex = 0
            Me.dtmFrom.Value = Format(Today.Day, 0.0#) & "/" & Format(Today.Month, 0.0#) & "/" & Today.Year.ToString
        Else
            MessageBox.Show("Không có thiết bị giao tiếp 2 chiều!", "Giao tiếp 2 chiều")
            Exit Sub
        End If
    End Sub


    Private Sub cmdGetDevice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetDevice.Click
        Dim ptbl As New DataTable
        Dim ptbl1 As New DataTable
        'Dim pFromDate, pToDate As String
        Dim pTestDate As String

        If Me.chkTestDate.Checked Then
            pTestDate = Me.dtmFrom.Text
        Else
            pTestDate = " "
        End If


        If Me.clsControls.spGet2WayDataControl(Me.tblDevice.Rows(Me.cboDevice.SelectedIndex).Item("Device_ID"), Me.tblDevice.Rows(Me.cboDevice.SelectedIndex).Item("TestType_ID"), pTestDate, ptbl, ptbl1) Then
            Me.tblDataConTrol = ptbl
            Me.tblPatient = ptbl1

            Me.grdPatientinfor.DataSource = Me.tblPatient.DefaultView
            Me.grdTestList.DataSource = Me.tblDataConTrol.DefaultView
        Else
            MessageBox.Show("Chưa khai báo tham số cho thiết bị này!", "Giao tiếp 2 chiều")
            Exit Sub
        End If
    End Sub

    Private Sub chkTestDate_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTestDate.CheckedChanged
        If Me.chkTestDate.Checked Then
            Me.dtmFrom.Enabled = True
        Else
            Me.dtmFrom.Enabled = False
        End If
    End Sub

    Private Sub cmdSaveRequest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveRequest.Click
        Dim cls As New clsControls
        Dim iCount As Int16
        Dim bChon As Boolean = False
        Try

            For iCount = 0 To Me.tblDataConTrol.Rows.Count - 1
                If Me.tblDataConTrol.Rows(iCount).Item("CHON") Then
                    cls.spSaveRegTestList(Me.tblPatient.Rows(Me.grdPatientinfor.CurrentRow.Index).Item("Barcode"), Me.tblPatient.Rows(Me.grdPatientinfor.CurrentRow.Index).Item("Test_ID"), Me.tblDataConTrol.Rows(iCount).Item("Alias_name"), Me.tblDataConTrol.Rows(iCount).Item("Data_name"))
                    Me.tblDataConTrol.Rows(iCount).Item("CHON") = False
                    bChon = True
                End If
            Next
            If bChon Then
                Me.tblPatient.Rows.RemoveAt(Me.grdPatientinfor.CurrentRow.Index)
            Else
                MessageBox.Show("Bạn chưa chọn Test!", "Test Select")

            End If


        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try


    End Sub


    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Close()
    End Sub
End Class